angular.module(moduleName)

  .run(function($ionicPlatform,$rootScope,$ionicHistory,TIPS) {
    $ionicPlatform.ready(function() {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
        cordova.plugins.Keyboard.disableScroll(true);

      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
      }
    });
    $rootScope.dialogs = [];
    $rootScope.TIPS = TIPS.getTips();

    //头部返回和客服
    $rootScope.leftItem = [{
      icon:'img/system_back.png',
      click:$rootScope.leftClick
    }];

    $rootScope.rightItem = [{
      icon:'img/system_contact.png',
      click:$rootScope.rightClick
    }];

    //监听isHideTabs状态，控制显示和隐藏标题栏
    $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
        $rootScope.title = toState.title;
        if(toState.hiddenTabs){
            $rootScope.isHideTabs = true;
        } else {
            $rootScope.isHideTabs = false;
        }
        if(toState.hiddenHeader){
            $rootScope.isHideHeader = true;
        } else {
            $rootScope.isHideHeader = false;
        }
      if(toState.hiddenBack){
        $rootScope.isHiddenBack = true;
      } else {
        $rootScope.isHiddenBack = false;
      }
    });

    $rootScope.goBack = function () {
      $ionicHistory.goBack();
    };

    $rootScope.leftClick = function() {
      $ionicHistory.goBack();
    };

    $rootScope.rightClick = function() {
      $state.go('helpOnline');
    }
  });
